/**
 * Created by 001 on 2017/9/12.
 */
/*弹出框*/
var PopView = Vue.extend({
    props: ['question', 'ack', 'cancel', 'cancelColor', 'ackColor'],
    template: '<div id="pop-view">' +
    '<div id="mask">' +
    '<div id="pop">' +
    '<p>{{question}}</p>' +
    '<div><span @click="accept" v-bind:style="{ color: ackColor}">{{ack}}</span><label @click="deny" v-bind:style="{ color: cancelColor}">{{cancel}}</label></div>' +
    '</div>' +
    '</div>' +
    '</div>',
    data: function () {
        return {}
    },
    methods: {
        accept: function () {
            this.$emit('confirm')
        },
        deny: function () {
            this.$emit('cancel')
        }
    }
});

/*提示框*/
var PromptView = Vue.extend({
    template: '<div id="prompt-view">' +
    '<transition name="fade">' +
    '<template v-if="showMessage">' +
    '<div id="message">' +
    '<span>{{message}}</span>' +
    '</div>' +
    '</template>' +
    '</transition>' +
    '</div>',
    data: function () {
        return {
            showMessage: false,
            message: ""
        }
    },
    created: function () {
    },
    methods: {
        /*提示信息*/
        toast: function (message) {

            if (window.webkit && window.webkit.messageHandlers) { // iphone
                window.webkit.messageHandlers.jsShowToast.postMessage(message);
                return;
            } else if (window.android && window.android.jsShowToast) {
                window.android.jsShowToast(message);
                return;
            }

            this.message = message
            this.showMessage = true
            var that = this
            setTimeout(function () {
                that.showMessage = false
            }, 1000)
        },
        toastInWechat: function (message) {
            this.message = message
            this.showMessage = true
            var that = this
            setTimeout(function () {
                that.showMessage = false
            }, 1000)
        }
    }
});

/*页面加载loading*/
var LoadingView = Vue.extend({
    template: '<div id="loading-view">' +
    '<div id="mask" class="trans-back">' +
    '<img src="/imgs/course/loading.gif" class="loading">' +
    '</div>' +
    '</div>',
    data: function () {
        return {}
    },
    methods: {}
});
//全局注册组件
Vue.component('prompt-view', PromptView);
Vue.component('pop-view', PopView);
Vue.component('loading-view', LoadingView);